﻿using Qy.Common;
using Qy.Models;
using Qy.Repository;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Qy.Service
{
    [AppService]
    public class LogLoginService
    {
        private readonly LogLoginRepository _LogLogin;

        public LogLoginService(LogLoginRepository LogLoginRepository)
        {
            _LogLogin = LogLoginRepository;
        }

        /// <summary>
        /// 获取全部列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<Page<ViewLogLogin>> GetSqlListAsync(int page, int limit, int uid)
        {
            return await _LogLogin.GetSqlListAsync(page, limit, uid, "Id desc");
        }

        public async Task<object> InsertLogLoginAsync(int userId, string ip)
        {
            LogLogin logSql = new()
            {
                UserId = userId,
                Ip = ip,
                Time = DateTime.Now
            };
            return await _LogLogin.InsertAsync(logSql);
        }
        public async Task<int> Clear()
        {
            return await _LogLogin.Clear();
        }
    }
}
